package com.yanfan.alarm.controller;

import java.util.Arrays;
import java.util.List;
import javax.validation.Valid;
import javax.servlet.http.HttpServletResponse;
import com.yanfan.common.utils.DateUtils;
import com.yanfan.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.alarm.domain.NjAlarmRecord;
import com.yanfan.alarm.service.INjAlarmRecordService;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.common.core.page.TableDataInfo;

/**
 * 报警事件记录Controller
 *
 * @author genluo
 * @date 2024-11-06
 */
@Api(tags = "报警事件记录")
@RestController
@RequestMapping("/alarm/alarmRecord")
public class NjAlarmRecordController extends BaseController {
    @Autowired
    private INjAlarmRecordService njAlarmRecordService;

    /**
     * 查询报警事件记录列表
     */
    @ApiOperation("报警事件记录分页列表")
    @PreAuthorize("@ss.hasPermi('alarm:alarmRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(NjAlarmRecord njAlarmRecord) {
        startPage();
        List<NjAlarmRecord> list = njAlarmRecordService.queryPageList(njAlarmRecord);
        return getDataTable(list);
    }

    /**
     * 导出报警事件记录列表
     */
    @ApiOperation("导出报警事件记录列表")
    @PreAuthorize("@ss.hasPermi('alarm:alarmRecord:export')")
    @Log(title = "报警事件记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NjAlarmRecord njAlarmRecord) {
        List<NjAlarmRecord> list = njAlarmRecordService.queryPageList(njAlarmRecord);
        ExcelUtil<NjAlarmRecord> util = new ExcelUtil<NjAlarmRecord>(NjAlarmRecord.class);
        util.exportExcel(response, list, "报警事件记录数据");
    }

    /**
     * 获取报警事件记录详细信息
     */
    @ApiOperation("获取报警事件记录详细信息")
    @PreAuthorize("@ss.hasPermi('alarm:alarmRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(njAlarmRecordService.getById(id));
    }

    /**
     * 新增报警事件记录
     */
    @ApiOperation("新增报警事件记录")
    @PreAuthorize("@ss.hasPermi('alarm:alarmRecord:add')")
    @Log(title = "报警事件记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody NjAlarmRecord njAlarmRecord) {
        return toAjax(njAlarmRecordService.save(njAlarmRecord));
    }

    /**
     * 修改报警事件记录
     */
    @ApiOperation("修改报警事件记录")
    @PreAuthorize("@ss.hasPermi('alarm:alarmRecord:edit')")
    @Log(title = "报警事件记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody NjAlarmRecord njAlarmRecord) {
        return toAjax(njAlarmRecordService.updateById(njAlarmRecord));
    }

    /**
     * 删除报警事件记录
     */
    @ApiOperation("删除报警事件记录")
    @PreAuthorize("@ss.hasPermi('alarm:alarmRecord:remove')")
    @Log(title = "报警事件记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(njAlarmRecordService.removeBatchByIds(Arrays.asList(ids)));
    }
}
